package persistence;

import java.sql.ResultSet;
import java.sql.SQLException;

import persistence.model.Post;
import utilities.FileInput;

public class PostDaoImplTest {
	
	public static void main(String[] args) {
		
		PostDaoImpl postDao = new PostDaoImpl();
		String fileAddress = "C:\\Users\\asl\\Desktop\\Roy\\IR pj\\teach\\comp433\\2005b\\assign\\data\\post1.txt";
		
		FileInput file = new FileInput(fileAddress);
		
		//postDao.deleteAll();
		
		insertFileToPost(file, postDao);
		
	}
	
	public static void insertFileToPost(FileInput file, PostDaoImpl postDao){
		int count = 0;
		while( file.hasNextLine()){
			String fileText = file.nextLine();
			String[] textParts = fileText.split(" ");
			
			Post post = new Post();
			
			post.setTerm(textParts[0]);
			post.setFileID(Integer.parseInt(textParts[1]));
			post.setWordPost(Integer.parseInt(textParts[2]));
			
			postDao.insert(post);
			
		}
		
		System.out.println("insert completed");
		
	}
	
	public static void select(PostDaoImpl postDao){
		
		ResultSet rs = postDao.selectAll();
		
		try {
			
			while(rs.next()){
				rs.getString(1);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
	}
	
	

}
